<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>第二个spark页面</title>

    <script src="https://cdn.bootcss.com/echarts/4.2.1-rc1/echarts.js"></script>
    <link href="https://cdn.bootcss.com/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet">
    <script src="re/macarons.js"></script>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
</head>
<body>

<div class="container-fluid">
    <div class="row">
        <div id="main" class="col-md-12" style="height:600px;">

        </div>
    </div>
</div>

<script type="text/javascript">
    // 基于准备好的dom，初始化echarts实例

    function getUrlParam(name) {

        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象

        var r = window.location.search.substr(1).match(reg);  //匹配目标参数

        if (r != null) return unescape(r[2]);

        return null; //返回参数值

    }

    $(function () {

        getData();
    })

    function getData() {
        var id=getUrlParam("id")
        $.ajax({
            url:'/getLast/'+id,
            type:'get',
            success:function (result) {
                getLast(result.time,result.ratings);
            }
        });
    }

    function getLast(x,y) {
        var myChart = echarts.init(document.getElementById('main'),'macarons');


        // 指定图表的配置项和数据
        var option = {
            title : {
                text: '某个电影的打分情况',
                subtext: '基于spark'
            },
            tooltip : {
                trigger: 'axis'
            },
            toolbox: {
                show : true,
                feature : {
                    mark : {show: true},
                    dataView : {show: true, readOnly: false},
                    magicType : {show: true, type: ['line', 'bar']},
                    restore : {show: true},
                    saveAsImage : {show: true}
                }
            },
            calculable : true,
            xAxis : [
                {
                    type : 'category',
                    boundaryGap : false,
                    data : x,
                    axisTick: {
                        alignWithLabel: true
                    }
                }
            ],
            yAxis : [
                {
                    type : 'value',
                }
            ],
            series : [
                {
                    name:'平均',
                    type:'line',
                    data:y,
                    markPoint : {
                        data : [
                            {type : 'max', name: '最大值'},
                            {type : 'min', name: '最小值'}
                        ]
                    },
                    markLine : {
                        data : [
                            {type : 'average', name: '平均值'}
                        ]
                    }
                }
            ]
        };

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    }

</script>

</body>
</html>